package com.rxkj.mapper;

import com.rxkj.entity.sys.NavMenu;
import com.rxkj.entity.sys.NavMenuVo;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface NavMenuMapper {

    List<NavMenu> getNavMenus(@Param("id") Integer id, @Param("userName") String userName);

    List<NavMenu> getNavMenu(@Param("id") Integer id, @Param("userName") String userName);

    List<NavMenu> getTreeMenus();

    List<NavMenu> getRoleMenus(@Param("id") Integer id, @Param("roleName") String roleName);

    int delete(Integer id);

    int addRoleMenus(@Param("id")Integer id,@Param("integer")Integer[] integer);

    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    @Insert("insert into sys_menu(pid, menuName,menuLevel, menuUrl, menuIcon,menuOrder,menuRemark,createTime) values(#{pid}, #{menuName},#{menuLevel}, #{menuUrl}, #{menuIcon}, #{menuOrder}, #{menuRemark},now())")
    int AddMenus(NavMenu navMenu);

    @Select("select id from sys_role where enabled = 1")
    @ResultType(Integer.class)
    List<Integer> getRoleId();

    int AddRoleMenus(@Param("roleId")List<Integer> roleId, Long mid);

    @Delete("update sys_menu set enabled=0 WHERE id = #{id}")
    void DeleteMenu(Integer id);

    @Delete("update sys_rolemenu set enabled=0 WHERE mid = #{id}")
    void DeleteRoleMenu(Integer id);

    @Update("UPDATE sys_menu\n" +
            "        SET menuName=#{menuName},\n" +
            "            menuIcon=#{menuIcon},\n" +
            "            menuOrder=#{menuOrder},\n" +
            "            menuRemark=#{menuRemark}\n" +
            "        WHERE id = #{id}")
    @ResultType(Integer.class)
    int EditMenu(NavMenu navMenu);

    @Select("select count(*) from sys_menu where menuUrl = #{menuUrl}")
    @ResultType(Integer.class)
    int getMenuUrlMenus(String menuUrl);

    @Select("select * from sys_menu where enabled=1 order by menuOrder asc")
    @ResultType(NavMenuVo.class)
    List<NavMenuVo> getAllMenus();

    @Select("select * from sys_menu where id = #{id} and enabled=1")
    @ResultType(NavMenu.class)
    NavMenu getMenuId(Integer id);

    @Select("select * from sys_menu where pid = #{id} and enabled=1")
    @ResultType(Integer.class)
    List<Integer> getChildrenIdsByPid(Integer pid);
}
